package homework03.test02;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class Test02 {

    public static void main(String[] args) {

        List<Worker> lst = new ArrayList<>();

        lst.add(new Worker("凤姐", 18, 20000));
        lst.add(new Worker("欧阳锋", 60, 8000));
        lst.add(new Worker("刘德华", 40, 30000));

        System.out.println("lst = " + lst);

        for (int i = 0;i < lst.size();i++) {
            Worker worker = lst.get(i);
            if ("欧阳锋".equals(worker.getName())) {
                lst.add(i, new Worker("张柏芝", 35, 3300));
                break;
            }
        }

        for (int i = 0;i < lst.size();i++) {
            Worker worker = lst.get(i);
            if ("刘德华".equals(worker.getName())) {
                lst.remove(i);
                break;
            }
        }

        for (int i = 0;i < lst.size();i++) {
            System.out.println(lst.get(i));
        }

        Iterator<Worker> iterator = lst.iterator();
        while (iterator.hasNext()) {
            Worker worker = iterator.next();
            worker.work();
        }

        System.out.println("lst = " + lst);
    }
}
